package com.jxw.utils;

import android.content.ContentValues;
import android.database.Cursor;
import android.net.Uri;
import android.util.Log;
import com.jxw.launcher.MyApp;

/* loaded from: classes.dex */
public class UserDBUtil {
    public static final String AGE = "_age";
    public static final String GRADE = "_grade";
    public static final String ID = "_id";
    public static final String IMAGE = "_image";
    public static final Uri LAST_RECORDR_URI = Uri.parse("content://com.jxw.mskt.video.userInfoProvider/userinfo");
    public static final String NICKNAME = "_nickname";
    public static final String SECTION = "_section";
    public static final String SEX = "_sex";

    public static void keepLastRecord(String str, String str2, int i, int i2, String str3, byte[] bArr) {
        if (hasLastRecocrd()) {
            updateLastRecord(str, str2, i, i2, str3, bArr);
        } else {
            insertLastRecord(str, str2, i, i2, str3, bArr);
        }
    }

    public static void insertLastRecord(String str, String str2, int i, int i2, String str3, byte[] bArr) {
        Log.e("lyx", "---5261656546-7-" + str + "-" + str2 + "-" + bArr);
        ContentValues contentValues = new ContentValues();
        if (str != null) {
            contentValues.put(SECTION, str);
        }
        if (str2 != null) {
            contentValues.put(GRADE, str2);
        }
        contentValues.put(SEX, Integer.valueOf(i));
        contentValues.put(AGE, Integer.valueOf(i2));
        if (str3 != null) {
            contentValues.put(NICKNAME, str3);
        }
        if (bArr != null) {
            contentValues.put(IMAGE, bArr);
        }
        try {
            Log.e("lyx", "---5261656546-8-" + contentValues.toString());
            MyApp.getInstance().getContentResolver().insert(LAST_RECORDR_URI, contentValues);
        } catch (Exception unused) {
        }
    }

    public static void updateLastRecord(String str, String str2, int i, int i2, String str3, byte[] bArr) {
        ContentValues contentValues = new ContentValues();
        if (str != null) {
            contentValues.put(SECTION, str);
        }
        if (str2 != null) {
            contentValues.put(GRADE, str2);
        }
        contentValues.put(SEX, Integer.valueOf(i));
        contentValues.put(AGE, Integer.valueOf(i2));
        if (str3 != null) {
            contentValues.put(NICKNAME, str3);
        }
        if (bArr != null) {
            contentValues.put(IMAGE, bArr);
        }
        try {
            Log.e("lyx", "---5261656546-8-" + contentValues.toString());
            int update = MyApp.getInstance().getContentResolver().update(LAST_RECORDR_URI, contentValues, null, null);
            Log.d("更新状态", update + "");
        } catch (Exception unused) {
        }
    }

    /* JADX WARN: Code restructure failed: missing block: B:10:0x0021, code lost:
        r1.close();
     */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct code enable 'Show inconsistent code' option in preferences
    */
    public static boolean hasLastRecocrd() {
        /*
            r0 = 0
            com.jxw.launcher.MyApp r1 = com.jxw.launcher.MyApp.getInstance()     // Catch: java.lang.Exception -> L24
            android.content.ContentResolver r2 = r1.getContentResolver()     // Catch: java.lang.Exception -> L24
            android.net.Uri r3 = com.jxw.utils.UserDBUtil.LAST_RECORDR_URI     // Catch: java.lang.Exception -> L24
            r4 = 0
            r5 = 0
            r6 = 0
            r7 = 0
            r8 = 0
            android.database.Cursor r1 = r2.query(r3, r4, r5, r6, r7, r8)     // Catch: java.lang.Exception -> L24
            r2 = 1
            if (r1 == 0) goto L1f
            int r3 = r1.getCount()     // Catch: java.lang.Exception -> L24
            if (r3 >= r2) goto L1e
            goto L1f
        L1e:
            r0 = 1
        L1f:
            if (r1 == 0) goto L24
            r1.close()     // Catch: java.lang.Exception -> L24
        L24:
            return r0
        */
        throw new UnsupportedOperationException("Method not decompiled: com.jxw.utils.UserDBUtil.hasLastRecocrd():boolean");
    }

    public static UserInfoBean getUserInfoRecocrd() {
        UserInfoBean userInfoBean = null;
        try {
            Cursor query = MyApp.getInstance().getContentResolver().query(LAST_RECORDR_URI, null, null, null, null);
            if (query != null && query.getCount() > 0) {
                UserInfoBean userInfoBean2 = new UserInfoBean();
                while (query.moveToNext()) {
                    try {
                        userInfoBean2.setSection(query.getString(query.getColumnIndex(SECTION)));
                        userInfoBean2.setUserIamge(query.getBlob(query.getColumnIndex(IMAGE)));
                        userInfoBean2.setGrade(query.getString(query.getColumnIndex(GRADE)));
                        userInfoBean2.setSex(query.getInt(query.getColumnIndex(SEX)));
                        userInfoBean2.setAge(query.getInt(query.getColumnIndex(AGE)));
                        userInfoBean2.setNickname(query.getString(query.getColumnIndex(NICKNAME)));
                    } catch (Exception unused) {
                        return userInfoBean2;
                    }
                }
                userInfoBean = userInfoBean2;
            }
            if (query != null) {
                query.close();
                return userInfoBean;
            }
            return userInfoBean;
        } catch (Exception unused2) {
            return userInfoBean;
        }
    }
}
